package algorithm.shortestpath;

public class Edge<Weight extends Number & Comparable> implements  Comparable<Edge> {
                                                                //Comparable

    private int a, b;    // 边的两个端点

    private Weight weight;  // 边的权值


    public Edge(int a, int b, Weight weight) {
        this.a = a;
        this.b = b;
        this.weight = weight;
    }

 public Edge(Edge<Weight> edge){

        this.a = edge.a;
        this.b = edge.b;
        this.weight=edge.weight;

 }

 public  int a(){
        return a;
 }

 public int b(){
        return  b;
 }

 public Weight wt(){

        return  weight;
 }

 public int getOther(int x){

        return  x==a?b:a;
 }

    @Override
    public String toString() {
        return "Edge{" +
                "a=" + a +
                ", b=" + b +
                ", weight=" + weight +
                '}';
    }


    @Override
    public int compareTo(Edge that) {

        if(this.weight.compareTo(that.wt())>0){
            return 1;
        }
        if(this.weight.compareTo(that.wt())<0){
            return  -1;
        }
        else{
            return 0;
        }
    }
}
